package array

import "sort"

func findWinners(matches [][]int) [][]int {
	res := make([][]int, 2)
	for i := range res {
		res[i] = make([]int, 0)
	}
	loseCnt := make(map[int]int)
	winCnt := make(map[int]int)
	for _, match := range matches {
		winner := match[0]
		loser := match[1]
		loseCnt[loser]++
		winCnt[winner]++
	}
	for k := range winCnt {
		if a, ok := loseCnt[k]; ok {
			if a == 1 {
				res[1] = append(res[1], k)
			}
			if a == 0 {
				res[0] = append(res[0], k)
			}
		} else {
			res[0] = append(res[0], k)
		}
	}
	for k, v := range loseCnt {
		if v == 1 {
			if _, ok := winCnt[k]; !ok {
				res[1] = append(res[1], k)
			}
		}
	}
	sort.Ints(res[0])
	sort.Ints(res[1])
	return res
}
